(function(){
	var AjaxCrud = QualityCheck.AjaxCRUD;
	var serverUrl = QualityCheck.GPUD.ServiceConfig;
	var currentPage = 1;
	var pageSize = 10;
	$(function(){
		pageBtns();
		getDetail();
	});
	function pageBtns(){
		$("#back-to-table").unbind("click");
		$("#back-to-table").click(function(){
			$("#detail-show",parent.document).hide();
			$("#right-tables",parent.document).show();
		});
	}
	function getDetail(){
		processBegin("数据加载中······");
		var urlPaStr = $("#detail-show",parent.document).attr("src").split("?")[1];
		var paStr = urlPaStr.split("&");
		var grade = paStr[0].split("=")[1];
		var classcode = paStr[1].split("=")[1];
		var type = paStr[2].split("=")[1];
		var userKey = $("#user-name",parent.parent.parent.document).attr("key");
		var schoolcode = $("#user-name",parent.parent.parent.document).attr("schoolcode");
//		var grade = $("#st-grade option:selected").val();
		var starttime = strToDate($("#start-time",parent.document).val() + ":00");
		var endtime = strToDate($("#end-time",parent.document).val() + ":00");
		var shtype = $("#st-type option:selected",parent.document).val();
		if(classcode == "" && grade == ""){
			grade = $("#student-grade option:selected",parent.document).val();
			classcode = $("#student-class option:selected",parent.document).val();
		}
		var obj = {
				starttime:starttime+"",
				endtime:endtime+"",
				type:type,
				schoolcode:schoolcode,
				classinfo:{
					classcode:classcode,
					grade:grade
				}
		};
		var data = {
				cmd:"getAttendanceByPage",
				model:"attendance",
				userKey:userKey,
				data:obj,
				remark:"",
				
		};
		AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
			var content = "";
			if(res.result == 1 && res.data != undefined && res.data != ""){
				if(res.data.data.length > 0){
					$("#detail-html").empty();
					$("#detail-html").html(_.template($("#detail-template").html(),res.data.data));
					processEnd("加载成功");
					
					$(".table-trs").unbind("hover");
					$(".table-trs").hover(function(){
						$(this).find(".table-operate").show();
					},function(){
						$(".table-operate").hide();
					});
					
					$(".signin-btn").unbind("click");
					$(".signin-btn").click(function(){
						var studentcode = $(this).attr("studentcode");
						var attencetime = $(this).attr("time");
						deleteBox("确定要补签吗？",function(){
							var obj = {
									studentcode:studentcode,
									time:attencetime
							};
							var data = {
									cmd:"AttendanceRetroactiveByStudentcode",
									model:"attendance",
									userKey:userKey,
									data:obj,
									remark:"",
							};
							AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
								processBegin("数据加载中······");
								if(res.result == 1 && res.data != undefined && res.data != ""){
									processEnd("补签成功");
									setTimeout(getDetail,500);
//									getDetail();
								}else{
									processError("补签失败");
								}
							},null,null);	
						});
						
					});
				}else{
					content += "<div class=\"table-trs\">" +
									"<div class=\"no-data-show\">没有查到相关结果！</div>" +
								"</div>";
					$("#detail-html").empty();
					$("#detail-html").append(content);
					processEnd("加载成功");
				}
				
			}else{
				content += "<div class=\"table-trs\">" +
								"<div class=\"no-data-show\">没有查到相关结果！</div>" +
							"</div>";
				$("#detail-html").empty();
				$("#detail-html").append(content);
				processError("加载失败");
			}
		},null,null);	
	}
})();